﻿package tools 
{
	import caurina.transitions.Tweener;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	
	/**
	* ...
	* @author Ben
	*/
	public class GraphicsTools 
	{
		
		public function GraphicsTools() 
		{
			
		}
		
		public static var directLie:String
		
		public static function getVeilSh(w:int, h:int, color:uint):Shape
		{
			
			trace(color);
			
			var bd:BitmapData = new BitmapData(2, 2, true, 0);
			bd.setPixel32(0, 1, color);
			bd.setPixel32(1, 0, color);
			var sh:Shape = new Shape();
			sh.graphics.beginBitmapFill(bd);
			//sh.graphics.beginFill(0xFF0000, 1);
			sh.graphics.drawRect(0, 0, w, h);
			sh.cacheAsBitmap = true;
			return sh;
		}
		
		public static function playIn(mc:Object)
		{
			mc["goto"] = mc.totalFrames;
			mc.addEventListener(Event.ENTER_FRAME, stepPlay);
		}
		
		public static function playOut(mc:Object)
		{
			mc["goto"] = 1;
			mc.addEventListener(Event.ENTER_FRAME, stepPlay);
		}
		
		public static function stepPlay(e:Event = null)
		{
			var f = e.target.currentFrame;
			if (f > e.target["goto"])
			{
				e.target.gotoAndStop( f-1 );
			}
			else if (f < e.target["goto"]) 
			{
				e.target.gotoAndStop(f+1);
			}
			else 
			{
				e.target.gotoAndStop(e.target["goto"]);
				e.target.removeEventListener(Event.ENTER_FRAME, stepPlay);
			}
		}
		
		public static function burn(ratio:Number):ColorTransform
		{
			var n:Number = 0xFF * ratio;
			return new ColorTransform(1, 1, 1, 1, n, n, n, 0);
		}
		
		public static function TweenBurn(dObj:DisplayObject, value:Number, duration:Number, begin:Number, d:Number=0)
		{
			var obj:Object = {value:begin};
			
			obj.func = function()
			{
				dObj.transform.colorTransform = burn(obj.value)
			}
			
			Tweener.addTween(obj, { value:value, time:duration, onUpdate:obj.func, delay:d} );
		}
		
		
		
	}
	
}
